<?php
    session_start();
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
            <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
            <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
            <script type="text/javascript" src="scripts/computer.js"></script>
    </head>
    <?php require 'header.html';
    ?>
    
<div id="container">
<div class="wrapper">
<div id="content">
<div id="order">    
    <body>
        <?php
        // put your code here
        $cardNum = $_POST["cardNum"];
        $cardName = $_POST["cardName"];
        $expDate = $_POST["expMonth"].$_POST["expYear"];
        
        $totalPrice = 0;
        $_SESSION["cardNum"] = $cardNum;
        $_SESSION["cardName"] = $cardName;
        $_SESSION["expDate"] = $expDate; 
        
        echo "Welcome customer ".$_SESSION["firstName"]." ".$_SESSION["lastName"];
        
        $con = mysql_connect("localhost", "zhouzhao", "19831022");
        if(!$con){
            die("could not connect to DB: ".mysql_error());
        }
        
        mysql_select_db("cloudcom", $con);

        ?>
            <form method="post" name="shoppingCart" action="placeOrder.php">
                
                <?php
                    $result = mysql_query("select * from customers where customerID = ".$_SESSION["customerID"]);
                    while($row = mysql_fetch_assoc($result)){
                        echo "Billing address: ".$row["street"]." ".$row["city"]." ".$row["state"]." ".$row["zip"]."<br/>";
                    }
                    echo "Credit card ending in ".substr($cardNum, 12)."<br/>";
                ?>
                
                <table border="1" id="cartTable">
                    <tr>
                        <th>Product Name</th>
                        <th>Product Description</th>
                        <th>Product Image</th>
                        <th>Product Price</th>
                        <th>Product Quantity</th>
                    </tr>
                    <?php
                        $result = mysql_query("select P.productName, P.productDescription, P.productImage, P.productPrice, S.productQuantity from shoppingCarts S, products P where S.productID = P.productID and S.sessionID='".$_SESSION["customerID"]."'"); 
                        while($row = mysql_fetch_array($result)){
                            echo "<tr>";
                            echo "<td>".$row["productName"]."</td>";
                            echo "<td>".$row["productDescription"]."</td>";
                            echo "<td><img src='images/products/".$row["productImage"]."' width='100' height='100' alt='image' /></td>";
                            echo "<td>".$row["productPrice"]."</td>";
                            echo "<td>".$row["productQuantity"]."</td>";
                            echo "</tr>";
                            $totalPrice = $totalPrice + $row["productPrice"]*$row["productQuantity"];
                        }
                        mysql_close($con);
                        $_SESSION["totalPrice"] = $totalPrice;
                        echo "Total Price: ".$totalPrice;
                    ?>
                </table>
                <input type="submit" value="Place Order" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
                
            </form>
            <?php
    if(isset($_SESSION["customerID"])){
    ?>
    <form method="post" name="logout" action="logout.php">
        <input type="submit" value="Logout" class="logoutStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
    </form>
    <?php
    }
    ?>
</div>	
</div>
<br class="clear" />
</div>
</div>
    
    <?php        require 'tail.html';
    ?>
    
    </body>
</html>
